/* ------------------------------------------------------------------------*
 *
 * ------------------------------------------------------------------------*/
#include "gd25q_cmd.h"
#include "gd25q_hal.h"
#include "gd25q_manage.h"
#include "osObjects.h"

q25_req_type *q25_req;

/*----------------------------------------------------------------------------
 *                             q25 task
 *---------------------------------------------------------------------------*/
void q25_task(void *argument)
{

    osDelay(10);
    gd25_spi_init();

    for (;;)
    {
        //rt_st = rt_mb_recv(qbid_flash, (rt_uint32_t *)&q25_req, INT32_MAX);

        //if(RT_EOK == rt_st)
        {
            q25_req->St = Q25_ST_BUSY;
            switch (q25_req->rw_mode)
            {
            case Q25_MODE_READ:
                gd25_read(q25_req->Addr, q25_req->Len, q25_req->data);
                break;
            case Q25_MODE_WRITE:
                gd25_write(q25_req->Addr, q25_req->Len, q25_req->data);
                break;
            case Q25_MODE_Sector_Erase:
                gd25_sector_erase(q25_req->Addr);
                break;
            case Q25_MODE_Block_Erase_32K:
                gd25_block_erase(q25_req->Addr);
                break;
            case Q25_MODE_Chip_Erase:
                gd25_chip_erase();
                break;
            default:
                break;
            }

            if (q25_req->CallBack)
                q25_req->CallBack();

            q25_req->St = Q25_ST_COMP;
        }
    }
}

/*----------------------------------------------------------------------------
 *                             q25 req
 *---------------------------------------------------------------------------*/
void q25_cmd_req(uint32_t q25_par_addr)
{
    //rt_mb_send(qbid_flash, q25_par_addr);
}
